package thread.learn;

/**
 * @author jiangwz
 * @create 2019/9/5.
 */
public class ThreadYield extends Thread {

    @Override
    public void run() {
        for (int x = 0; x < 100; x++) {
            System.out.println(getName() + ":" + x);
            // 当i为50时，该线程就会把CPU时间让掉，让其他或者自己的线程执行（也就是谁先抢到谁执行）
            if (x == 50){
                Thread.yield();
            }
            System.out.println(x);
        }
    }

    public static void main(String[] args){

        ThreadYield y1 = new ThreadYield();
        ThreadYield y2 = new ThreadYield();
        ThreadYield y3 = new ThreadYield();

        y1.setName("林青霞");
        y2.setName("至尊宝");
        y3.setName("牛魔王");

        y1.start();
//        y2.start();
//        y3.start();
    }
}
